<?php
include_once  'checkAdmin.php';
$id = $_GET['id'];
$action = $_GET['action'];
if(is_numeric($action) && is_numeric($id)){
    //is_numeric 判断变量值是否为数值或字符串数字返回true反之false
    if($action == 1 || $action==0){
        //设置管理员
        $sql = "update info set admin = $action where id = $id";
    }else{
        echo "
            <script>
            alert('参数错误')
            history.back()
            </script>";
    }
    include_once  'conn.php';
    $result = mysqli_query($conn, $sql);
    if($action){
        $msg = '设置管理员';
    }else{
        $msg = '取消管理员';
    }
    if($result){
        echo "
            <script>
            alert('{$msg}成功')
            location.href = 'admin.php'
            </script>";
    }else{
        echo "
            <script>
            alert('{$msg}失败')
            history.back()
            </script>";
    }
}else{
    echo "
            <script>
            alert('参数错误')
            history.back()
            </script>";
}
